function Page(el,array,func) {
    this.el = el;
    // console.log(this.el)
    this.count = 0;
    if(array.count){
        this.count = parseInt(array.count);
    }
    this.limit = 10;
    if(array.limit){
        this.limit = array.limit;
    }
    this.page = 1;
    this.zongpage = Math.ceil(this.count/this.limit);
    var str = '';
    if(array.head){
        str +='<div class="shou">首页</div>';
    }
    if(array.upper){
        str+='<div class="shang">上一页</div>';
    }
    this.active = 'xuanzhong';
    if(array.active){
        this.active = array.active;
    }
    this.xian = 5;
    if(this.zongpage<this.xian){
        this.xian = this.zongpage;
    }
    str+='<div class="qian" style="display: none">···</div>';
    for (var a=0;a<this.xian;a++){
        if(a==0){
            str +='<div class="curr '+this.active+'">'+(a+1)+'</div>';
        }else{
            str +='<div class="curr">'+(a+1)+'</div>';
        }
    }
    if(this.zongpage>5){
        str+='<div class="hou">···</div>';
    }else {
        str+='<div class="hou" style="display: none">···</div>';
    }
    if(array.upper){
        str+='<div class="xia">下一页</div>';
    }
    if(array.head){
        str+='<div class="wei">尾页</div>';
    }
    //console.log(str)
    this.el.append(str);
    var that = this;
    //重排版事件
    function cong(){
        var jiou =  that.el.find('.curr');
        // console.log(that.page);
        $.each(jiou,function (i,v) {
            if(that.page-2<=1||that.zongpage<=5){
                $(v).text(i+1);
                that.el.find('.qian').hide();
                if(that.zongpage>5){
                    that.el.find('.hou').show();
                }
            }else if(that.page+2>that.zongpage){
                if(that.zongpage>5&&that.page>3){
                    that.el.find('.qian').show();
                }else{
                    that.el.find('.qian').hide();
                }
                if(that.zongpage<that.page+2){
                    that.el.find('.hou').hide();
                }
                $(v).text(that.zongpage-4+i);
            }else{
                if(that.zongpage>5&&that.page>3){
                    that.el.find('.qian').show();
                    that.el.find('.hou').show();
                }
                if(that.page<that.zongpage-2){
                    that.el.find('.hou').show();
                }else{
                    that.el.find('.hou').hide();
                }
                $(v).text(that.page-2+i);
            }
        });
        var curr = that.el.find('.curr');
        var index = '';
        $.each(curr,function (i,v) {
            index = parseInt($(v).text());
            if(index==that.page){
                $(v).addClass(that.active);
            }else{
                $(v).removeClass(that.active);
            }
        })
        var tiaojian = {page:that.page,limit:that.limit};
        func(tiaojian,that);
    }
    //首页点击事件
    this.el.find('.shou').click(function(){
        that.page = 1;
        cong();
    });
    //尾页点击事件
    this.el.find('.wei').click(function(){
        that.page = that.zongpage;
        cong();
    })
    //上一页点击事件
    this.el.find('.shang').click(function () {
        var number = parseInt(that.page);
        if(number>1){
            number--;
        }else{
            number =1;
        }
        that.page = number;
        cong();
    });
    //下一页点击事件
    this.el.find('.xia').click(function () {
        var number = parseInt(that.page);
        if(number<that.zongpage){
            number++;
        }else{
            number = that.zongpage;
        }
        that.page = number;
        cong();
    });
    //数字被点击事件
    this.el.find('.curr').click(function () {
        var number = parseInt($(this).text());
        that.page = number;
        cong();
    });
    //点击qian的函数
    this.el.find('.qian').click(function () {
        var text = parseInt(that.el.find('.curr').eq(0).text());
        if(text-2>=1){
            that.page = text-2;
        }else{
            that.page=1;
        }
        cong();
    });
    //点击后的函数
    this.el.find('.hou').click(function () {
        var text = parseInt(that.el.find('.curr').eq(4).text());
        console.log(text);
        if(text+3<that.zongpage){
            that.page = text+3;
        }else{
            that.page = that.zongpage;
        }
        cong();
    });
}